<template>
  <div>
    <el-input
        size='small'
        v-model="input"
        placeholder="请输入内容"
        clearable
        maxlength="64"
        style="width:15%"
        show-word-limit
    ></el-input>
    <el-button
        size="small"
        style="margin-left: 20px;"
        @click="wordsSend"
    >发送</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      input: '',
      sensitiveWords: ["sdasd","adadDad"],
    };
  },
  methods: {
    wordsSend() {
        const sensitiveWords = this.sensitiveWords;
        // 将敏感词列表转换为正则表达式，以便于匹配
        const regex = new RegExp(sensitiveWords.join('|'), 'g');
        // 使用String.prototype.replace方法替换敏感词
        this.input = this.input.replace(regex, '**')
        return this.input
      },
    queryItemInfo() {
      var self = this;
      self.$axios.get('/sensitive/list').then((res) =>{
        if(res.data.code === 200){
          res.data.data.forEach(ele =>{
            this.sensitiveWords.push(ele.sensitive)
          })
        }
      });
    },
  },
  mounted() {
    this.queryItemInfo()
  }
}
</script>

<style scoped>

</style>
